import logging

import pydash

__LEVEL = "DEBUG"
__NAME = "internal"


def get_internal_logger(sub_name: str = "") -> logging.Logger:
    """获取一个指定名称的内部 Logger

    Args:
        sub_name: 子组件名称
    """
    logger = logging.getLogger(__NAME)
    logging.addLevelName(logging.DEBUG, "DEBU")
    logging.addLevelName(logging.WARN, "WARN")
    logging.addLevelName(logging.WARNING, "WARN")
    logging.addLevelName(logging.ERROR, "ERRO")

    if len(logger.handlers) == 0:
        logger.setLevel(__LEVEL)
        formatter = logging.Formatter('%(asctime)s [%(levelname)s] [%(name)s] %(message)s')

        ch = logging.StreamHandler()
        ch.setFormatter(formatter)
        logger.addHandler(ch)

    _name = __NAME
    if not pydash.is_empty(sub_name):
        _name = ".".join([__NAME, sub_name])

    return logging.getLogger(_name)
